#include <bits/stdc++.h>
// 2025/01/23
// tag: 
// Author: Zhang Muen
using namespace std;

int q, n, pushed[100001], poped[100001];

signed main()
{
    cin >> q;
    while (q--){
        cin >> n;
        int l = -1, r = 0;
        for (int i = 0; i < n; i++)
            cin >> pushed[i];
        for (int i = 0; i < n; i++)
            cin >> poped[i];
        stack<int> st;
        while (r < n && l < n){
            if (st.empty() || st.top() != poped[r])
                st.push(pushed[++l]);
            else
                st.pop(), r++;
        }
        if (r < n)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    return 0;
}